import App from './App'
import store from './store';
import messages from './locale/index'
let i18nConfig = {
	locale: uni.getLocale(),
	messages
}
// #ifndef VUE3
import Vue from 'vue'
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
const i18n = new VueI18n(i18nConfig)
import './uni.promisify.adaptor'
import utils from './utils/utils'
Vue.use(utils)
const httpRequest = require("@/common/httpRequest.js")
const lbtpriview = (index, arr) => { //预览图片
	console.log("预览图片");
	var i = arr; //获取当前页面的轮播图数据
	//uniapp预览轮播图
	uni.previewImage({
		current: index, //预览图片的下标
		urls: i //预览图片的地址,必須要数组形式,如果不是数组形式就转换成数组形式就可以
	})
}
const daohang = (val) => {
	let text = "https://www.google.com.tw/maps/place/" + val
	location.href = text;
}
const returnKmUnit = (m) => {
	var v;
	if (typeof m === 'number' && !isNaN(m)) {
		if (m >= 1000) {
			v = (m / 1000).toFixed(2) + 'km'
		} else {
			v = Number(m).toFixed(2) + 'm'
		}
	} else {
		v = '0m'
	}
	return v;
}
const phone = (p) => { //拨打電話
	console.log("拨打電話");
	uni.makePhoneCall({
		phoneNumber: p.toString()
	}).catch((e) => {
		// console.log(e)  //用catch(e)来捕獲錯误{makePhoneCall:fail cancel}
	})
}
const jumpdetail = (url, val) => {
	console.log("跳转详情");
	uni.navigateTo({
		url: url + val,
		fail(err) {
			console.log("跳轉頁面出錯", err);
		}
	})
}
const jumpurl = (url) => {
	uni.navigateTo({
		url: url
	})
}
const timereturn = (time3) => {
	//将時間戳格式转换成年月日时分秒
	var date = new Date(time3);
	var Y = date.getFullYear() + '-';
	var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
	var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';

	var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
	var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
	var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
	var strDate = Y + M + D + h + m + s;
	return strDate

}
const returnzftext = (val) => {
	if (val == 1) return "點數支付"
	if (val == 2) return "多元支付"
	if (val == 3) return "現金支付"
	if (val == 4) return "信用卡"
	if (val == 5) return "linepay線上支付"
	if (val == 6) return "街口線上支付"
	if (val == 7) return "街口線下支付"
	if (val == 8) return "linepay線下支付"
}
const returnxxjsTime = (time1, time2) => {
	// 取得當前時間
	const now = new Date(time1);
	// 加 5 小時
	now.setHours(now.getHours() + Number(time2));
	// 格式化輸出（年月日時分秒）
	const formattedDateTime = now.toLocaleString(); // 簡易格式化
	return formattedDateTime.replace(/\//g, "-");
}
const khrzisShow = (item) => {
	if (Number(new Date()) >= Number(new Date(item.start_date_text))) {
		return true
	} else {
		return false
	}
}
const backpage = () => {
	uni.navigateBack(1)
}
const copy = (value) => {
	uni.setClipboardData({
		data: value, //要被复制的内容
		success: () => {
			//复制成功的回调函数
			httpRequest.toast("複製成功")
		}
	});
}
const maskMiddle = (str) => {
  if (str.length <= 6) {
    // 长度不足6位时全部显示（或根据需求调整）
    return str;
  }
  return str.slice(0, 3) + "***" + str.slice(-3);
}

Vue.prototype.http = httpRequest
Vue.prototype.lbtpriview = lbtpriview
Vue.prototype.phone = phone
Vue.prototype.daohang = daohang
Vue.prototype.returnKmUnit = returnKmUnit
Vue.prototype.jumpdetail = jumpdetail
Vue.prototype.jumpurl = jumpurl
Vue.prototype.timereturn = timereturn
Vue.prototype.returnzftext = returnzftext
Vue.prototype.returnxxjsTime = returnxxjsTime
Vue.prototype.khrzisShow = khrzisShow
Vue.prototype.backpage = backpage
Vue.prototype.copy = copy
Vue.prototype.maskMiddle = maskMiddle
Vue.config.productionTip = false
App.mpType = 'app'
Vue.prototype.$store = store;
const app = new Vue({
	...App,
	store
})
app.$mount()
// #endif
import uView from "uview-ui";
Vue.use(uView);
import globalPopup from '@/components/globalPopup/globalPopup.js';
Vue.use(globalPopup);
// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
import {
	createI18n
} from 'vue-i18n'
export function createApp() {
	const app = createSSRApp(App)
	app.use(i18n)
	return {
		app
	}
}
// #endif